<!DOCTYPE html>


<html lang="en">
  

    <head>
      <meta charset="utf-8" />
        
      <meta name="description" content="時光的个人博客" />
      
      <meta
        name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1"
      />
	  <meta name="referrer" content="no-referrer" />

      <title>Git常用命令速查 |  時光</title>
  <meta name="generator" content="hexo-theme-ayer">
      
      <link rel="shortcut icon" href="/favicon.ico" />
       
<link rel="stylesheet" href="/dist/main.css">

      
<link rel="stylesheet" href="/css/fonts/remixicon.css">

      
<link rel="stylesheet" href="/css/custom.css">
 
      <script src="https://cdn.staticfile.org/pace/1.2.4/pace.min.js"></script>
       
 

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-bulma@5.0.1/bulma.min.css"
      />
      <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.19/dist/sweetalert2.min.js"></script>

      <!-- mermaid -->
      
      <style>
        .swal2-styled.swal2-confirm {
          font-size: 1.6rem;
        }
      </style>
    <link rel="alternate" href="/atom.xml" title="時光" type="application/atom+xml">
</head>
  </html>
</html>


<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-Git 常用命令速查"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  Git常用命令速查
</h1>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2022/01/22/Git%20%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%E9%80%9F%E6%9F%A5/" class="article-date">
  <time datetime="2022-01-22T15:09:16.390Z" itemprop="datePublished">2022-01-22</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E5%A5%BD%E8%AE%B0%E6%80%A7%E4%B8%8D%E5%A6%82%E7%83%82%E7%AC%94%E5%A4%B4/">好记性不如烂笔头</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> Word count:</span>
            <span class="post-count">5.1k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> Reading time≈</span>
            <span class="post-count">21 min</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="一、-Git常用命令速查"><a href="#一、-Git常用命令速查" class="headerlink" title="一、 Git常用命令速查"></a>一、 Git常用命令速查</h2><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><span class="line">git branch <span class="comment"># 查看本地所有分支</span></span><br><span class="line">git status <span class="comment"># 查看当前状态 </span></span><br><span class="line">git commit <span class="comment"># 提交 </span></span><br><span class="line">git branch -a <span class="comment"># 查看所有的分支</span></span><br><span class="line">git branch -r <span class="comment"># 查看远程所有分支</span></span><br><span class="line">git commit -am <span class="string">&quot;init&quot;</span> <span class="comment"># 提交并且加注释 </span></span><br><span class="line">git remote add origin git@192.168.1.119:ndshow</span><br><span class="line">git push origin master <span class="comment"># 将文件给推到服务器上 </span></span><br><span class="line">git remote show origin <span class="comment"># 显示远程库origin里的资源 </span></span><br><span class="line">git push origin master:develop</span><br><span class="line">git push origin master:hb-dev <span class="comment"># 将本地库与服务器上的库进行关联 </span></span><br><span class="line">git checkout --track origin/dev <span class="comment"># 切换到远程dev分支</span></span><br><span class="line">git branch -D master develop <span class="comment"># 删除本地库develop</span></span><br><span class="line">git checkout -b dev <span class="comment"># 建立一个新的本地分支dev</span></span><br><span class="line">git merge origin/dev <span class="comment"># 将分支dev与当前分支进行合并</span></span><br><span class="line">git checkout dev <span class="comment"># 切换到本地dev分支</span></span><br><span class="line">git remote show <span class="comment"># 查看远程库</span></span><br><span class="line">git add .</span><br><span class="line">git <span class="built_in">rm</span> 文件名(包括路径) <span class="comment"># 从git中删除指定文件</span></span><br><span class="line">git <span class="built_in">clone</span> git://github.com/schacon/grit.git <span class="comment"># 从服务器上将代码给拉下来</span></span><br><span class="line">git config --list <span class="comment"># 看所有用户</span></span><br><span class="line">git ls-files <span class="comment"># 看已经被提交的</span></span><br><span class="line">git <span class="built_in">rm</span> [file name] <span class="comment"># 删除一个文件</span></span><br><span class="line">git commit -a <span class="comment"># 提交当前repos的所有的改变</span></span><br><span class="line">git add [file name] <span class="comment"># 添加一个文件到git index</span></span><br><span class="line">git commit -v <span class="comment"># 当你用－v参数的时候可以看commit的差异</span></span><br><span class="line">git commit -m <span class="string">&quot;This is the message describing the commit&quot;</span> <span class="comment"># 添加commit信息</span></span><br><span class="line">git commit -a <span class="comment"># -a是代表add，把所有的change加到git index里然后再commit</span></span><br><span class="line">git commit -a -v <span class="comment"># 一般提交命令</span></span><br><span class="line">git <span class="built_in">log</span> <span class="comment"># 看你commit的日志</span></span><br><span class="line">git diff <span class="comment"># 查看尚未暂存的更新</span></span><br><span class="line">git <span class="built_in">rm</span> a.a <span class="comment"># 移除文件(从暂存区和工作区中删除)</span></span><br><span class="line">git <span class="built_in">rm</span> --cached a.a <span class="comment"># 移除文件(只从暂存区中删除)</span></span><br><span class="line">git commit -m <span class="string">&quot;remove&quot;</span> <span class="comment"># 移除文件(从Git中删除)</span></span><br><span class="line">git <span class="built_in">rm</span> -f a.a <span class="comment"># 强行移除修改后文件(从暂存区和工作区中删除)</span></span><br><span class="line">git diff --cached 或 $ git diff --staged <span class="comment"># 查看尚未提交的更新</span></span><br><span class="line">git stash push <span class="comment"># 将文件给push到一个临时空间中</span></span><br><span class="line">git stash pop <span class="comment"># 将文件从临时空间pop下来</span></span><br><span class="line">\---------------------------------------------------------</span><br><span class="line">git remote add origin git@github.com:username/Hello-World.git</span><br><span class="line">git push origin master <span class="comment"># 将本地项目给提交到服务器中</span></span><br><span class="line">\-----------------------------------------------------------</span><br><span class="line">git pull <span class="comment"># 本地与服务器端同步</span></span><br><span class="line">\-----------------------------------------------------------------</span><br><span class="line">git push (远程仓库名) (分支名) <span class="comment"># 将本地分支推送到服务器上去。</span></span><br><span class="line">git push origin serverfix:awesomebranch</span><br><span class="line">\------------------------------------------------------------------</span><br><span class="line">git fetch <span class="comment"># 相当于是从远程获取最新版本到本地，不会自动merge</span></span><br><span class="line">git commit -a -m <span class="string">&quot;log_message&quot;</span> <span class="comment"># (-a是提交所有改动，-m是加入log信息) 本地修改同步至服务器端 ：</span></span><br><span class="line">git branch branch_0.1 master <span class="comment"># 从主分支master创建branch_0.1分支</span></span><br><span class="line">git branch -m branch_0.1 branch_1.0 <span class="comment"># 将branch_0.1重命名为branch_1.0</span></span><br><span class="line">git checkout branch_1.0/master <span class="comment"># 切换到branch_1.0/master分支</span></span><br><span class="line"><span class="built_in">du</span> -hs</span><br><span class="line"></span><br><span class="line">git branch <span class="comment"># 删除远程branch</span></span><br><span class="line">git push origin :branch_remote_name</span><br><span class="line">git branch -r -d branch_remote_name</span><br></pre></td></tr></table></figure>

<p>初始化版本库，并提交到远程服务器端</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">mkdir</span> WebApp</span><br><span class="line"><span class="built_in">cd</span> WebApp</span><br><span class="line">git init <span class="comment"># 本地初始化</span></span><br><span class="line"><span class="built_in">touch</span> README</span><br><span class="line">git add README <span class="comment"># 添加文件</span></span><br><span class="line">git commit -m <span class="string">&#x27;first commit&#x27;</span></span><br><span class="line">git remote add origin git@github.com:daixu/WebApp.git</span><br></pre></td></tr></table></figure>

<p>增加一个远程服务器端</p>
<p>上面的命令会增加URL地址为‘<a href="mailto:&#103;&#105;&#x74;&#64;&#103;&#105;&#x74;&#104;&#117;&#98;&#x2e;&#x63;&#x6f;&#109;">&#103;&#105;&#x74;&#64;&#103;&#105;&#x74;&#104;&#117;&#98;&#x2e;&#x63;&#x6f;&#109;</a>:daixu&#x2F;WebApp.git’，名称为origin的远程服务器库，以后提交代码的时候只需要使用 origin别名即可</p>
<h2 id="二、-Git-命令速查表"><a href="#二、-Git-命令速查表" class="headerlink" title="二、 Git 命令速查表"></a>二、 Git 命令速查表</h2><h3 id="1、常用的Git命令"><a href="#1、常用的Git命令" class="headerlink" title="1、常用的Git命令"></a>1、常用的Git命令</h3><table>
<thead>
<tr>
<th>命令</th>
<th>简要说明</th>
</tr>
</thead>
<tbody><tr>
<td>git add</td>
<td>添加至暂存区</td>
</tr>
<tr>
<td>git add–interactive</td>
<td>交互式添加</td>
</tr>
<tr>
<td>git apply</td>
<td>应用补丁</td>
</tr>
<tr>
<td>git am</td>
<td>应用邮件格式补丁</td>
</tr>
<tr>
<td>git annotate</td>
<td>同义词，等同于 git blame</td>
</tr>
<tr>
<td>git archive</td>
<td>文件归档打包</td>
</tr>
<tr>
<td>git bisect</td>
<td>二分查找</td>
</tr>
<tr>
<td>git blame</td>
<td>文件逐行追溯</td>
</tr>
<tr>
<td>git branch</td>
<td>分支管理</td>
</tr>
<tr>
<td>git cat-file</td>
<td>版本库对象研究工具</td>
</tr>
<tr>
<td>git checkout</td>
<td>检出到工作区、切换或创建分支</td>
</tr>
<tr>
<td>git cherry-pick</td>
<td>提交拣选</td>
</tr>
<tr>
<td>git citool</td>
<td>图形化提交，相当于 git gui 命令</td>
</tr>
<tr>
<td>git clean</td>
<td>清除工作区未跟踪文件</td>
</tr>
<tr>
<td>git clone</td>
<td>克隆版本库</td>
</tr>
<tr>
<td>git commit</td>
<td>提交</td>
</tr>
<tr>
<td>git config</td>
<td>查询和修改配置</td>
</tr>
<tr>
<td>git describe</td>
<td>通过里程碑直观地显示提交ID</td>
</tr>
<tr>
<td>git diff</td>
<td>差异比较</td>
</tr>
<tr>
<td>git difftool</td>
<td>调用图形化差异比较工具</td>
</tr>
<tr>
<td>git fetch</td>
<td>获取远程版本库的提交</td>
</tr>
<tr>
<td>git format-patch</td>
<td>创建邮件格式的补丁文件。参见 git am 命令</td>
</tr>
<tr>
<td>git grep</td>
<td>文件内容搜索定位工具</td>
</tr>
<tr>
<td>git gui</td>
<td>基于Tcl&#x2F;Tk的图形化工具，侧重提交等操作</td>
</tr>
<tr>
<td>git help</td>
<td>帮助</td>
</tr>
<tr>
<td>git init</td>
<td>版本库初始化</td>
</tr>
<tr>
<td>git init-db*</td>
<td>同义词，等同于 git init</td>
</tr>
<tr>
<td>git log</td>
<td>显示提交日志</td>
</tr>
<tr>
<td>git merge</td>
<td>分支合并</td>
</tr>
<tr>
<td>git mergetool</td>
<td>图形化冲突解决</td>
</tr>
<tr>
<td>git mv</td>
<td>重命名</td>
</tr>
<tr>
<td>git pull</td>
<td>拉回远程版本库的提交</td>
</tr>
<tr>
<td>git push</td>
<td>推送至远程版本库</td>
</tr>
<tr>
<td>git rebase</td>
<td>分支变基</td>
</tr>
<tr>
<td>git rebase–interactive</td>
<td>交互式分支变基</td>
</tr>
<tr>
<td>git reflog</td>
<td>分支等引用变更记录管理</td>
</tr>
<tr>
<td>git remote</td>
<td>远程版本库管理</td>
</tr>
<tr>
<td>git repo-config*</td>
<td>同义词，等同于 git config</td>
</tr>
<tr>
<td>git reset</td>
<td>重置改变分支“游标”指向</td>
</tr>
<tr>
<td>git rev-parse</td>
<td>将各种引用表示法转换为哈希值等</td>
</tr>
<tr>
<td>git revert</td>
<td>反转提交</td>
</tr>
<tr>
<td>git rm</td>
<td>删除文件</td>
</tr>
<tr>
<td>git show</td>
<td>显示各种类型的对象</td>
</tr>
<tr>
<td>git stage*</td>
<td>同义词，等同于 git add</td>
</tr>
<tr>
<td>git stash</td>
<td>保存和恢复进度</td>
</tr>
<tr>
<td>git status</td>
<td>显示工作区文件状态</td>
</tr>
<tr>
<td>git tag</td>
<td>里程碑管理</td>
</tr>
</tbody></table>
<h3 id="2、对象库操作相关命令"><a href="#2、对象库操作相关命令" class="headerlink" title="2、对象库操作相关命令"></a>2、对象库操作相关命令</h3><table>
<thead>
<tr>
<th>命令</th>
<th>简要说明</th>
</tr>
</thead>
<tbody><tr>
<td>git commit-tree</td>
<td>从树对象创建提交</td>
</tr>
<tr>
<td>git hash-object</td>
<td>从标准输入或文件计算哈希值或创建对象</td>
</tr>
<tr>
<td>git ls-files</td>
<td>显示工作区和暂存区文件</td>
</tr>
<tr>
<td>git ls-tree</td>
<td>显示树对象包含的文件</td>
</tr>
<tr>
<td>git mktag</td>
<td>读取标准输入创建一个里程碑对象</td>
</tr>
<tr>
<td>git mktree</td>
<td>读取标准输入创建一个树对象</td>
</tr>
<tr>
<td>git read-tree</td>
<td>读取树对象到暂存区</td>
</tr>
<tr>
<td>git update-index</td>
<td>工作区内容注册到暂存区及暂存区管理</td>
</tr>
<tr>
<td>git unpack-file</td>
<td>创建临时文件包含指定 blob 的内容</td>
</tr>
<tr>
<td>git write-tree</td>
<td>从暂存区创建一个树对象</td>
</tr>
</tbody></table>
<h3 id="3、引用操作相关命令"><a href="#3、引用操作相关命令" class="headerlink" title="3、引用操作相关命令"></a>3、引用操作相关命令</h3><table>
<thead>
<tr>
<th>命令</th>
<th>简要说明</th>
</tr>
</thead>
<tbody><tr>
<td>git check-ref-format</td>
<td>检查引用名称是否符合规范</td>
</tr>
<tr>
<td>git for-each-ref</td>
<td>引用迭代器，用于shell编程</td>
</tr>
<tr>
<td>git ls-remote</td>
<td>显示远程版本库的引用</td>
</tr>
<tr>
<td>git name-rev</td>
<td>将提交ID显示为友好名称</td>
</tr>
<tr>
<td>git peek-remote*</td>
<td>过时命令，请使用 git ls-remote</td>
</tr>
<tr>
<td>git rev-list</td>
<td>显示版本范围</td>
</tr>
<tr>
<td>git show-branch</td>
<td>显示分支列表及拓扑关系</td>
</tr>
<tr>
<td>git show-ref</td>
<td>显示本地引用</td>
</tr>
<tr>
<td>git symbolic-ref</td>
<td>显示或者设置符号引用</td>
</tr>
<tr>
<td>git update-ref</td>
<td>更新引用的指向</td>
</tr>
<tr>
<td>git verify-tag</td>
<td>校验 GPG 签名的Tag</td>
</tr>
</tbody></table>
<h3 id="4、版本库管理相关命令"><a href="#4、版本库管理相关命令" class="headerlink" title="4、版本库管理相关命令"></a>4、版本库管理相关命令</h3><table>
<thead>
<tr>
<th>命令</th>
<th>简要说明</th>
</tr>
</thead>
<tbody><tr>
<td>git count-objects</td>
<td>显示松散对象的数量和磁盘占用</td>
</tr>
<tr>
<td>git filter-branch</td>
<td>版本库重构</td>
</tr>
<tr>
<td>git fsck</td>
<td>对象库完整性检查</td>
</tr>
<tr>
<td>git fsck-objects*</td>
<td>同义词，等同于 git fsck</td>
</tr>
<tr>
<td>git gc</td>
<td>版本库存储优化</td>
</tr>
<tr>
<td>git index-pack</td>
<td>从打包文件创建对应的索引文件</td>
</tr>
<tr>
<td>git lost-found*</td>
<td>过时，请使用 git fsck –lost-found 命令</td>
</tr>
<tr>
<td>git pack-objects</td>
<td>从标准输入读入对象ID，打包到文件</td>
</tr>
<tr>
<td>git pack-redundant</td>
<td>查找多余的 pack 文件</td>
</tr>
<tr>
<td>git pack-refs</td>
<td>将引用打包到 .git&#x2F;packed-refs 文件中</td>
</tr>
<tr>
<td>git prune</td>
<td>从对象库删除过期对象</td>
</tr>
<tr>
<td>git prune-packed</td>
<td>将已经打包的松散对象删除</td>
</tr>
<tr>
<td>git relink</td>
<td>为本地版本库中相同的对象建立硬连接</td>
</tr>
<tr>
<td>git repack</td>
<td>将版本库未打包的松散对象打包</td>
</tr>
<tr>
<td>git show-index</td>
<td>读取包的索引文件，显示打包文件中的内容</td>
</tr>
<tr>
<td>git unpack-objects</td>
<td>从打包文件释放文件</td>
</tr>
<tr>
<td>git verify-pack</td>
<td>校验对象库打包文件</td>
</tr>
</tbody></table>
<h3 id="5、数据传输相关命令"><a href="#5、数据传输相关命令" class="headerlink" title="5、数据传输相关命令"></a>5、数据传输相关命令</h3><table>
<thead>
<tr>
<th>命令</th>
<th>简要说明</th>
</tr>
</thead>
<tbody><tr>
<td>git fetch-pack</td>
<td>执行 git fetch 或 git pull 命令时在本地执行此命令，用于从其他版本库获取缺失的对象</td>
</tr>
<tr>
<td>git receive-pack</td>
<td>执行 git push 命令时在远程执行的命令，用于接受推送的数据</td>
</tr>
<tr>
<td>git send-pack</td>
<td>执行 git push 命令时在本地执行的命令，用于向其他版本库推送数据</td>
</tr>
<tr>
<td>git upload-archive</td>
<td>执行 git archive –remote 命令基于远程版本库创建归档时，远程版本库执行此命令传送归档</td>
</tr>
<tr>
<td>git upload-pack</td>
<td>执行 git fetch 或 git pull 命令时在远程执行此命令，将对象打包、上传</td>
</tr>
</tbody></table>
<h3 id="6、邮件相关命令"><a href="#6、邮件相关命令" class="headerlink" title="6、邮件相关命令"></a>6、邮件相关命令</h3><table>
<thead>
<tr>
<th>命令</th>
<th>简要说明</th>
</tr>
</thead>
<tbody><tr>
<td>git imap-send</td>
<td>将补丁通过 IMAP 发送</td>
</tr>
<tr>
<td>git mailinfo</td>
<td>从邮件导出提交说明和补丁</td>
</tr>
<tr>
<td>git mailsplit</td>
<td>将 mbox 或 Maildir 格式邮箱中邮件逐一提取为文件</td>
</tr>
<tr>
<td>git request-pull</td>
<td>创建包含提交间差异和执行PULL操作地址的信息</td>
</tr>
<tr>
<td>git send-email</td>
<td>发送邮件</td>
</tr>
</tbody></table>
<h3 id="7、协议相关命令"><a href="#7、协议相关命令" class="headerlink" title="7、协议相关命令"></a>7、协议相关命令</h3><table>
<thead>
<tr>
<th>命令</th>
<th>简要说明</th>
</tr>
</thead>
<tbody><tr>
<td>git daemon</td>
<td>实现Git协议</td>
</tr>
<tr>
<td>git http-backend</td>
<td>实现HTTP协议的CGI程序，支持智能HTTP协议</td>
</tr>
<tr>
<td>git instaweb</td>
<td>即时启动浏览器通过 gitweb 浏览当前版本库</td>
</tr>
<tr>
<td>git shell</td>
<td>受限制的shell，提供仅执行Git命令的SSH访问</td>
</tr>
<tr>
<td>git update-server-info</td>
<td>更新哑协议需要的辅助文件</td>
</tr>
<tr>
<td>git http-fetch</td>
<td>通过HTTP协议获取版本库</td>
</tr>
<tr>
<td>git http-push</td>
<td>通过HTTP&#x2F;DAV协议推送</td>
</tr>
<tr>
<td>git remote-ext</td>
<td>由Git命令调用，通过外部命令提供扩展协议支持</td>
</tr>
<tr>
<td>git remote-fd</td>
<td>由Git命令调用，使用文件描述符作为协议接口</td>
</tr>
<tr>
<td>git remote-ftp</td>
<td>由Git命令调用，提供对FTP协议的支持</td>
</tr>
<tr>
<td>git remote-ftps</td>
<td>由Git命令调用，提供对FTPS协议的支持</td>
</tr>
<tr>
<td>git remote-http</td>
<td>由Git命令调用，提供对HTTP协议的支持</td>
</tr>
<tr>
<td>git remote-https</td>
<td>由Git命令调用，提供对HTTPS协议的支持</td>
</tr>
<tr>
<td>git remote-testgit</td>
<td>协议扩展示例脚本</td>
</tr>
</tbody></table>
<h3 id="8、版本库转换和交互相关命令"><a href="#8、版本库转换和交互相关命令" class="headerlink" title="8、版本库转换和交互相关命令"></a>8、版本库转换和交互相关命令</h3><table>
<thead>
<tr>
<th>命令</th>
<th>简要说明</th>
</tr>
</thead>
<tbody><tr>
<td>git archimport</td>
<td>导入Arch版本库到Git</td>
</tr>
<tr>
<td>git bundle</td>
<td>提交打包和解包，以便在不同版本库间传递</td>
</tr>
<tr>
<td>git cvsexportcommit</td>
<td>将Git的一个提交作为一个CVS检出</td>
</tr>
<tr>
<td>git cvsimport</td>
<td>导入CVS版本库到Git。或者使用 cvs2git</td>
</tr>
<tr>
<td>git cvsserver</td>
<td>Git的CVS协议模拟器，可供CVS命令访问Git版本库</td>
</tr>
<tr>
<td>git fast-export</td>
<td>将提交导出为 git-fast-import 格式</td>
</tr>
<tr>
<td>git fast-import</td>
<td>其他版本库迁移至Git的通用工具</td>
</tr>
<tr>
<td>git svn</td>
<td>Git 作为前端操作 Subversion</td>
</tr>
</tbody></table>
<h3 id="9、合并相关的辅助命令"><a href="#9、合并相关的辅助命令" class="headerlink" title="9、合并相关的辅助命令"></a>9、合并相关的辅助命令</h3><table>
<thead>
<tr>
<th>命令</th>
<th>简要说明</th>
</tr>
</thead>
<tbody><tr>
<td>git merge-base</td>
<td>供其他脚本调用，找到两个或多个提交最近的共同祖先</td>
</tr>
<tr>
<td>git merge-file</td>
<td>针对文件的两个不同版本执行三向文件合并</td>
</tr>
<tr>
<td>git merge-index</td>
<td>对index中的冲突文件调用指定的冲突解决工具</td>
</tr>
<tr>
<td>git merge-octopus</td>
<td>合并两个以上分支。参见 git merge 的octopus合并策略</td>
</tr>
<tr>
<td>git merge-one-file</td>
<td>由 git merge-index 调用的标准辅助程序</td>
</tr>
<tr>
<td>git merge-ours</td>
<td>合并使用本地版本，抛弃他人版本。参见 git merge 的ours合并策略</td>
</tr>
<tr>
<td>git merge-recursive</td>
<td>针对两个分支的三向合并。参见 git merge 的recursive合并策略</td>
</tr>
<tr>
<td>git merge-resolve</td>
<td>针对两个分支的三向合并。参见 git merge 的resolve合并策略</td>
</tr>
<tr>
<td>git merge-subtree</td>
<td>子树合并。参见 git merge 的 subtree 合并策略</td>
</tr>
<tr>
<td>git merge-tree</td>
<td>显式三向合并结果，不改变暂存区</td>
</tr>
<tr>
<td>git fmt-merge-msg</td>
<td>供执行合并操作的脚本调用，用于创建一个合并提交说明</td>
</tr>
<tr>
<td>git rerere</td>
<td>重用所记录的冲突解决方案</td>
</tr>
</tbody></table>
<h3 id="10、-杂项"><a href="#10、-杂项" class="headerlink" title="10、 杂项"></a>10、 杂项</h3><table>
<thead>
<tr>
<th>命令</th>
<th>简要说明</th>
</tr>
</thead>
<tbody><tr>
<td>git bisect–helper</td>
<td>由 git bisect 命令调用，确认二分查找进度</td>
</tr>
<tr>
<td>git check-attr</td>
<td>显示某个文件是否设置了某个属性</td>
</tr>
<tr>
<td>git checkout-index</td>
<td>从暂存区拷贝文件至工作区</td>
</tr>
<tr>
<td>git cherry</td>
<td>查找没有合并到上游的提交</td>
</tr>
<tr>
<td>git diff-files</td>
<td>比较暂存区和工作区，相当于 git diff –raw</td>
</tr>
<tr>
<td>git diff-index</td>
<td>比较暂存区和版本库，相当于 git diff –cached –raw</td>
</tr>
<tr>
<td>git diff-tree</td>
<td>比较两个树对象，相当于 git diff –raw A B</td>
</tr>
<tr>
<td>git difftool–helper</td>
<td>由 git difftool 命令调用，默认要使用的差异比较工具</td>
</tr>
<tr>
<td>git get-tar-commit-id</td>
<td>从 git archive 创建的 tar 包中提取提交ID</td>
</tr>
<tr>
<td>git gui–askpass</td>
<td>命令 git gui 的获取用户口令输入界面</td>
</tr>
<tr>
<td>git notes</td>
<td>提交评论管理</td>
</tr>
<tr>
<td>git patch-id</td>
<td>补丁过滤行号和空白字符后生成补丁唯一ID</td>
</tr>
<tr>
<td>git quiltimport</td>
<td>将Quilt补丁列表应用到当前分支</td>
</tr>
<tr>
<td>git replace</td>
<td>提交替换</td>
</tr>
<tr>
<td>git shortlog</td>
<td>对 git log 的汇总输出，适合于产品发布说明</td>
</tr>
<tr>
<td>git stripspace</td>
<td>删除空行，供其他脚本调用</td>
</tr>
<tr>
<td>git submodule</td>
<td>子模组管理</td>
</tr>
<tr>
<td>git tar-tree</td>
<td>过时命令，请使用 git archive</td>
</tr>
<tr>
<td>git var</td>
<td>显示 Git 环境变量</td>
</tr>
<tr>
<td>git web–browse</td>
<td>启动浏览器以查看目录或文件</td>
</tr>
<tr>
<td>git whatchanged</td>
<td>显示提交历史及每次提交的改动</td>
</tr>
<tr>
<td>git-mergetool–lib</td>
<td>包含于其他脚本中，提供合并&#x2F;差异比较工具的选择和执行</td>
</tr>
<tr>
<td>git-parse-remote</td>
<td>包含于其他脚本中，提供操作远程版本库的函数</td>
</tr>
<tr>
<td>git-sh-setup</td>
<td>包含于其他脚本中，提供 shell 编程的函数库</td>
</tr>
</tbody></table>
<p>Git 常用命令速查表。点击查看大图。</p>
<p><a target="_blank" rel="noopener" href="http://files.jb51.net/file_images/article/201409/git_big_jb51.jpg"><img src="http://files.jb51.net/file_images/article/201409/git_big_jb51.jpg" alt="img"></a></p>
<p>Git命令参考手册(文本版)</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br></pre></td><td class="code"><pre><span class="line">git init                         <span class="comment"># 初始化本地git仓库（创建新仓库） </span></span><br><span class="line">git config --global user.name <span class="string">&quot;xxx&quot;</span>            <span class="comment"># 配置用户名 </span></span><br><span class="line">git config --global user.email <span class="string">&quot;xxx@xxx.com&quot;</span>       <span class="comment"># 配置邮件 </span></span><br><span class="line">git config --global color.ui <span class="literal">true</span>             <span class="comment"># git status等命令自动着色 </span></span><br><span class="line">git config --global color.status auto </span><br><span class="line">git config --global color.diff auto </span><br><span class="line">git config --global color.branch auto </span><br><span class="line">git config --global color.interactive auto </span><br><span class="line">git <span class="built_in">clone</span> git+ssh://git@192.168.53.168/VT.git       <span class="comment"># clone远程仓库 </span></span><br><span class="line">git status                        <span class="comment"># 查看当前版本状态（是否修改） </span></span><br><span class="line">git add xyz                        <span class="comment"># 添加xyz文件至index </span></span><br><span class="line">git add .                         <span class="comment"># 增加当前子目录下所有更改过的文件至index </span></span><br><span class="line">git commit -m <span class="string">&#x27;xxx&#x27;</span>                    <span class="comment"># 提交 </span></span><br><span class="line">git commit --amend -m <span class="string">&#x27;xxx&#x27;</span>                <span class="comment"># 合并上一次提交（用于反复修改） </span></span><br><span class="line">git commit -am <span class="string">&#x27;xxx&#x27;</span>                   <span class="comment"># 将add和commit合为一步 </span></span><br><span class="line">git <span class="built_in">rm</span> xxx                        <span class="comment"># 删除index中的文件 </span></span><br><span class="line">git <span class="built_in">rm</span> -r *                        <span class="comment"># 递归删除 </span></span><br><span class="line">git <span class="built_in">log</span>                          <span class="comment"># 显示提交日志 </span></span><br><span class="line">git <span class="built_in">log</span> -1                        <span class="comment"># 显示1行日志 -n为n行 </span></span><br><span class="line">git <span class="built_in">log</span> -5</span><br><span class="line">git <span class="built_in">log</span> --<span class="built_in">stat</span>                      <span class="comment"># 显示提交日志及相关变动文件 </span></span><br><span class="line">git <span class="built_in">log</span> -p -m </span><br><span class="line">git show dfb02e6e4f2f7b573337763e5c0013802e392818     <span class="comment"># 显示某个提交的详细内容 </span></span><br><span class="line">git show dfb02                      <span class="comment"># 可只用commitid的前几位 </span></span><br><span class="line">git show HEAD                       <span class="comment"># 显示HEAD提交日志 </span></span><br><span class="line">git show HEAD^                      <span class="comment"># 显示HEAD的父（上一个版本）的提交日志 ^^为上两个版本 ^5为上5个版本 </span></span><br><span class="line">git tag                          <span class="comment"># 显示已存在的tag </span></span><br><span class="line">git tag -a v2.0 -m <span class="string">&#x27;xxx&#x27;</span>                 <span class="comment"># 增加v2.0的tag </span></span><br><span class="line">git show v2.0                       <span class="comment"># 显示v2.0的日志及详细内容 </span></span><br><span class="line">git <span class="built_in">log</span> v2.0                       <span class="comment"># 显示v2.0的日志 </span></span><br><span class="line">git diff                         <span class="comment"># 显示所有未添加至index的变更 </span></span><br><span class="line">git diff --cached                     <span class="comment"># 显示所有已添加index但还未commit的变更 </span></span><br><span class="line">git diff HEAD^                      <span class="comment"># 比较与上一个版本的差异 </span></span><br><span class="line">git diff HEAD -- ./lib                  <span class="comment"># 比较与HEAD版本lib目录的差异 </span></span><br><span class="line">git diff origin/master..master              <span class="comment"># 比较远程分支master上有本地分支master上没有的 </span></span><br><span class="line">git diff origin/master..master --<span class="built_in">stat</span>           <span class="comment"># 只显示差异的文件，不显示具体内容 </span></span><br><span class="line">git remote add origin git+ssh://git@192.168.53.168/VT.git <span class="comment"># 增加远程定义（用于push/pull/fetch） </span></span><br><span class="line">git branch                        <span class="comment"># 显示本地分支 </span></span><br><span class="line">git branch --contains 50089                <span class="comment"># 显示包含提交50089的分支 </span></span><br><span class="line">git branch -a                       <span class="comment"># 显示所有分支 </span></span><br><span class="line">git branch -r                       <span class="comment"># 显示所有原创分支 </span></span><br><span class="line">git branch --merged                    <span class="comment"># 显示所有已合并到当前分支的分支 </span></span><br><span class="line">git branch --no-merged                  <span class="comment"># 显示所有未合并到当前分支的分支 </span></span><br><span class="line">git branch -m master master_copy             <span class="comment"># 本地分支改名 </span></span><br><span class="line">git checkout -b master_copy                <span class="comment"># 从当前分支创建新分支master_copy并检出 </span></span><br><span class="line">git checkout -b master master_copy            <span class="comment"># 上面的完整版 </span></span><br><span class="line">git checkout features/performance             <span class="comment"># 检出已存在的features/performance分支 </span></span><br><span class="line">git checkout --track hotfixes/BJVEP933          <span class="comment"># 检出远程分支hotfixes/BJVEP933并创建本地跟踪分支</span></span><br><span class="line">git checkout v2.0                     <span class="comment"># 检出版本v2.0</span></span><br><span class="line">git checkout -b devel origin/develop           <span class="comment"># 从远程分支develop创建新本地分支devel并检出 </span></span><br><span class="line">git checkout -- README                  <span class="comment"># 检出head版本的README文件（可用于修改错误回退） </span></span><br><span class="line">git merge origin/master                  <span class="comment"># 合并远程master分支至当前分支 </span></span><br><span class="line">git cherry-pick ff44785404a8e               <span class="comment"># 合并提交ff44785404a8e的修改 </span></span><br><span class="line">git push origin master                  <span class="comment"># 将当前分支push到远程master分支 </span></span><br><span class="line">git push origin :hotfixes/BJVEP933            <span class="comment"># 删除远程仓库的hotfixes/BJVEP933分支 </span></span><br><span class="line">git push --tags                      <span class="comment"># 把所有tag推送到远程仓库 </span></span><br><span class="line">git fetch                         <span class="comment"># 获取所有远程分支（不更新本地分支，另需merge） </span></span><br><span class="line">git fetch --prune                     <span class="comment"># 获取所有原创分支并清除服务器上已删掉的分支 </span></span><br><span class="line">git pull origin master                  <span class="comment"># 获取远程分支master并merge到当前分支 </span></span><br><span class="line">git <span class="built_in">mv</span> README README2                   <span class="comment"># 重命名文件README为README2 </span></span><br><span class="line">git reset --hard HEAD                   <span class="comment"># 将当前版本重置为HEAD（通常用于merge失败回退） </span></span><br><span class="line">git rebase </span><br><span class="line">git branch -d hotfixes/BJVEP933              <span class="comment"># 删除分支hotfixes/BJVEP933（本分支修改已合并到其他分支） </span></span><br><span class="line">git branch -D hotfixes/BJVEP933              <span class="comment"># 强制删除分支hotfixes/BJVEP933 </span></span><br><span class="line">git ls-files                       <span class="comment"># 列出git index包含的文件 </span></span><br><span class="line">git show-branch                      <span class="comment"># 图示当前分支历史 </span></span><br><span class="line">git show-branch --all                   <span class="comment"># 图示所有分支历史 </span></span><br><span class="line">git whatchanged                      <span class="comment"># 显示提交历史对应的文件修改 </span></span><br><span class="line">git revert dfb02e6e4f2f7b573337763e5c0013802e392818    <span class="comment"># 撤销提交dfb02e6e4f2f7b573337763e5c0013802e392818 </span></span><br><span class="line">git ls-tree HEAD                     <span class="comment"># 内部命令：显示某个git对象 </span></span><br><span class="line">git rev-parse v2.0                    <span class="comment"># 内部命令：显示某个ref对于的SHA1 HASH </span></span><br><span class="line">git reflog                        <span class="comment"># 显示所有提交，包括孤立节点 </span></span><br><span class="line">git show HEAD@&#123;5&#125; </span><br><span class="line">git show master@&#123;yesterday&#125;                <span class="comment"># 显示master分支昨天的状态 </span></span><br><span class="line">git <span class="built_in">log</span> --pretty=format:<span class="string">&#x27;%h %s&#x27;</span> --graph          <span class="comment"># 图示提交日志 </span></span><br><span class="line">git show HEAD~3</span><br><span class="line">git show -s --pretty=raw 2be7fcb476 </span><br><span class="line">git stash                         <span class="comment"># 暂存当前修改，将所有至为HEAD状态 </span></span><br><span class="line">git stash list                      <span class="comment"># 查看所有暂存 </span></span><br><span class="line">git stash show -p stash@&#123;0&#125;                <span class="comment"># 参考第一次暂存 </span></span><br><span class="line">git stash apply stash@&#123;0&#125;                 <span class="comment"># 应用第一次暂存 </span></span><br><span class="line">git grep <span class="string">&quot;delete from&quot;</span>                  <span class="comment"># 文件中搜索文本“delete from” </span></span><br><span class="line">git grep -e <span class="string">&#x27;#define&#x27;</span> --and -e SORT_DIRENT </span><br><span class="line">git gc </span><br><span class="line">git fsck</span><br></pre></td></tr></table></figure>



<p><a target="_blank" rel="noopener" href="http://gitref.org/index.html">Git</a> 是一个很强大的分布式版本控制系统。它不但适用于管理大型开源软件的源代码，管理私人的文档和源代码也有很多优势。</p>
<h2 id="三、Git常用操作命令："><a href="#三、Git常用操作命令：" class="headerlink" title="三、Git常用操作命令："></a>三、Git常用操作命令：</h2><h3 id="1、远程仓库相关命令"><a href="#1、远程仓库相关命令" class="headerlink" title="1、远程仓库相关命令"></a>1、远程仓库相关命令</h3><p>检出仓库：<code>git clone git://github.com/jquery/jquery.git</code></p>
<p>查看远程仓库：<code> git remote -v</code></p>
<p>添加远程仓库：<code> git remote add [name] [url]</code></p>
<p>删除远程仓库：<code>git remote rm [name]</code></p>
<p>修改远程仓库：<code>git remote set-url --push [name] [newUrl]</code></p>
<p>拉取远程仓库：<code>git pull [remoteName] [localBranchName]</code></p>
<p>推送远程仓库：<code>git push [remoteName] [localBranchName]</code></p>
<p>如果想把本地的某个分支test提交到远程仓库，并作为远程仓库的master分支，或者作为另外一个名叫test的分支，如下：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git push origin <span class="built_in">test</span>:master     <span class="comment"># 提交本地test分支作为远程的master分支</span></span><br><span class="line"></span><br><span class="line">git push origin <span class="built_in">test</span>:<span class="built_in">test</span>        <span class="comment"># 提交本地test分支作为远程的test分支</span></span><br></pre></td></tr></table></figure>

<h3 id="2、分支-branch-操作相关命令"><a href="#2、分支-branch-操作相关命令" class="headerlink" title="2、分支(branch)操作相关命令"></a>2、分支(branch)操作相关命令</h3><p>查看本地分支： <code>git branch</code></p>
<p>查看远程分支： <code>git branch -r</code></p>
<p>创建本地分支： <code>git branch [name]</code> —-注意新分支创建后不会自动切换为当前分支</p>
<p>切换分支：<code>git checkout [name]</code></p>
<p>创建新分支并立即切换到新分支<code> git checkout -b [name]</code></p>
<p>删除分支： <code>git branch -d [name]</code> —- -d选项只能删除已经参与了合并的分支，对于未有合并的分支是无法删除的。如果想强制删除一个分支，可以使用-D选项</p>
<p>合并分支： <code>git merge [name]</code> —-将名称为[name]的分支与当前分支合并</p>
<p>创建远程分支(本地分支push到远程)： <code>git push origin [name]</code></p>
<p>删除远程分支： <code>git push origin :heads/[name]</code> 或  <code>gitpush origin :[name] </code></p>
<p>创建空的分支：(执行命令之前记得先提交你当前分支的修改，否则会被强制删干净没得后悔)</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">git symbolic-ref HEAD refs/heads/[name]</span><br><span class="line"></span><br><span class="line"><span class="built_in">rm</span> .git/index</span><br><span class="line"></span><br><span class="line">git clean -fdx</span><br></pre></td></tr></table></figure>

<h3 id="3、版本-tag-操作相关命令"><a href="#3、版本-tag-操作相关命令" class="headerlink" title="3、版本(tag)操作相关命令"></a>3、版本(tag)操作相关命令</h3><p>查看版本：<code>git tag</code></p>
<p>创建版本：<code>git tag [name]</code></p>
<p>删除版本：<code>git tag -d [name]</code></p>
<p>查看远程版本： <code>git tag -r</code></p>
<p>创建远程版本(本地版本push到远程)： <code>git push origin [name]</code></p>
<p>删除远程版本： <code>git push origin :refs/tags/[name]</code></p>
<p>合并远程仓库的tag到本地：<code>git pull origin --tags</code></p>
<p>上传本地tag到远程仓库： <code>git push origin --tags</code></p>
<p>创建带注释的tag： <code>git tag -a [name] -m &#39;yourMessage&#39;</code></p>
<h3 id="4、子模块-submodule-相关操作命令"><a href="#4、子模块-submodule-相关操作命令" class="headerlink" title="4、子模块(submodule)相关操作命令"></a>4、子模块(submodule)相关操作命令</h3><p>添加子模块：<code> git submodule add [url] [path]</code></p>
<p>  如：<code>git submodule add git://github.com/soberh/ui-libs.git src/main/webapp/ui-libs</code></p>
<p>初始化子模块： <code>git submodule init</code>  —-只在首次检出仓库时运行一次就行</p>
<p>更新子模块：<code>git submodule update</code> —-每次更新或切换分支后都需要运行一下</p>
<p>删除子模块：（分4步走哦）</p>
<ol>
<li><p><code>git rm --cached [path]</code></p>
</li>
<li><p>编辑“.gitmodules”文件，将子模块的相关配置节点删除掉</p>
</li>
<li><p>编辑“ .git&#x2F;config”文件，将子模块的相关配置节点删除掉</p>
</li>
<li><p>手动删除子模块残留的目录</p>
</li>
</ol>
<h3 id="5、忽略一些文件、文件夹不提交"><a href="#5、忽略一些文件、文件夹不提交" class="headerlink" title="5、忽略一些文件、文件夹不提交"></a>5、忽略一些文件、文件夹不提交</h3><p>在仓库根目录下创建名称为“.gitignore”的文件，写入不需要的文件夹名或文件，每个元素占一行即可，如</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">target</span><br><span class="line"></span><br><span class="line">bin</span><br><span class="line"></span><br><span class="line">*.db</span><br></pre></td></tr></table></figure>

<p>Git 常用命令图表 </p>
<p><img src="https://img-blog.csdn.net/20180620113451746?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hhbGFvZGE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="img"></p>
<blockquote>
<p>原文地址：<a target="_blank" rel="noopener" href="https://blog.csdn.net/halaoda/article/details/78661334">https://blog.csdn.net/halaoda/article/details/78661334</a></p>
</blockquote>
 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          Donate
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>Copyright： </strong>
          
          Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2022/01/22/Git%20%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%E9%80%9F%E6%9F%A5/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Git/" rel="tag">Git</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2022/06/07/SQL%E5%90%AB%E7%A9%BA%E6%A0%BC%E5%AD%97%E6%AE%B5%E6%9F%A5%E8%AF%A2%E6%96%B9%E5%BC%8F/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            SQL含空格字段查询方式
          
        </div>
      </a>
    
    
      <a href="/2022/01/22/Vscode%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">Vscode使用指南</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.staticfile.org/valine/1.4.16/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "dx3B54wOwhi75vxC2IAZagtg-gzGzoHsz",
    app_key: "m4k2fhnFa1iPI4vbofHqMY5X",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
   
  
   
    <script src="https://cdn.staticfile.org/twikoo/1.4.18/twikoo.all.min.js"></script>
    <div id="twikoo" class="twikoo"></div>
    <script>
        twikoo.init({
            envId: ""
        })
    </script>
 
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2023
        <i class="ri-heart-fill heart_icon"></i> Shiguang
      </li>
    </ul>
    <ul>
      <li>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></span>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>    
    </main>
    <div class="float_btns">
      <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

    </div>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="時光"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-3.6.0.min.js"></script>
 
<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->
 
<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: ".tocbot",
    contentSelector: ".article-entry",
    headingSelector: "h1, h2, h3, h4, h5, h6",
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: "main",
    positionFixedSelector: ".tocbot",
    positionFixedClass: "is-position-fixed",
    fixedSidebarOffset: "auto",
  });
</script>

<script src="https://cdn.staticfile.org/jquery-modal/0.9.2/jquery.modal.min.js"></script>
<link
  rel="stylesheet"
  href="https://cdn.staticfile.org/jquery-modal/0.9.2/jquery.modal.min.css"
/>
<script src="https://cdn.staticfile.org/justifiedGallery/3.8.1/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->
 <!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.staticfile.org/photoswipe/4.1.3/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.staticfile.org/photoswipe/4.1.3/default-skin/default-skin.min.css">
<script src="https://cdn.staticfile.org/photoswipe/4.1.3/photoswipe.min.js"></script>
<script src="https://cdn.staticfile.org/photoswipe/4.1.3/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script> 
<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->
 
<script src="/js/busuanzi-2.3.pure.min.js"></script>
 
<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->
 
<link rel="stylesheet" href="/css/clipboard.css">
 <script src="https://cdn.staticfile.org/clipboard.js/2.0.10/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>
 
<!-- CanvasBackground -->

<script>
  if (window.mermaid) {
    mermaid.initialize({ theme: "forest" });
  }
</script>


    
    

  </div>
</body>

</html>